import http from "@/api";
import { ResPage } from "@/api/interface";
import { Report } from "@/api/interface/iot";
import { dayjs } from "element-plus";

export enum StatDataType {
	//数据(字节)容量：
	DEV_DATA_SIZE = "DEV_DATA_SIZE",
	//数据条数：
	DEV_DATA_NUM = "DEV_DATA_NUM",
	//规则处理条数：
	DEV_RULE_PROCS = "DEV_RULE_PROCS",
	//转发条数：
	DATA_FORWARD_NUM = "DATA_FORWARD_NUM",
	//告警数：
	DATA_ALARM_NUM = "DATA_ALARM_NUM",
	//通知数：
	DATA_NOTIFY_NUM = "DATA_NOTIFY_NUM",
	//设备数：
	DEV_COUNT = "DEV_COUNT",
	//设备活跃数：
	DEV_ACTIVE_COUNT = "DEV_ACTIVE_COUNT",
	//用户数：
	USER_COUNT = "USER_COUNT",
	//用户活跃数：
	USER_ACTIVE_COUNT = "USER_ACTIVE_COUNT",
	//终端事件
	DEV_EVENT_LIST = "DEV_EVENT_LIST"
}
export const stat = (params: {
	dataType: StatDataType;
	startTime?: String;
	endTime?: String;
	intervalH?: Number;
	limitCount?: Number;
}) => {
	params.intervalH = params.intervalH || 24;
	params.startTime = params.startTime || dayjs().subtract(15, "d").format("YYYY-MM-DD 00:00:00");
	params.endTime = params.endTime || dayjs().format("YYYY-MM-DD 23:59:59");
	return http.get<ResPage<Report.StatDataInfo[]> | Report.StatDataInfo[]>(`/auth/data-stat/`, params, {
		headers: { noLoading: true }
	});
};

export const deviceTotalStat = () => {
	return iotThingStat({ type: "device" });
};
export const gatewayTotalStat = () => {
	return iotThingStat({ typeNot: "device" });
};
export const productTotalStat = () => {
	return iotThingStat({ byProduct: true });
};
/**
 * 设备统计
 * @param params
 * @returns
 * @example
 * 查网关 params = { typeNot: "device" };
 * 查设备 params = { type: "device" };
 * 查产品 params = { byProduct: true };
 */
const iotThingStat = (params: {
	deptId?: String;
	sn?: String;
	name?: String;
	search?: String;
	onlineStatus?: String;
	gatewaySn?: String;
	alarmStatus?: Boolean;
	address?: String;
	productModel?: String;
	typeNot?: "device";
	type?: "device";
	byProduct?: Boolean;
	productModelIn?: String[];
}) => {
	return http.get(`/device/stat/count`, params, {
		headers: { noLoading: true }
	});
};
